package android.slc.appbase.ui.vd;

import android.os.Bundle;
import android.slc.appbase.utils.AppIntentUtils;

import androidx.activity.result.ActivityResultCaller;
import androidx.activity.result.ActivityResultLauncher;

import java.io.Serializable;

/**
 * @Description:
 * @Author: sunlunchang
 * @CreateDate: 2022/10/12 下午 1:55
 */
public class SimpleRegisterActivityFastFunc<T extends Serializable> extends SimpleRegisterActivityFunc<T> {
    private ActivityResultLauncher<Bundle> activityResultLauncher;

    public SimpleRegisterActivityFastFunc(IntentTargetWrapper intentTargetWrapper) {
        super(intentTargetWrapper);
    }

    public SimpleRegisterActivityFastFunc(IntentTargetWrapper intentTargetWrapper, OnActivityResultCallback<T> OnActivityResultCallback) {
        super(intentTargetWrapper, OnActivityResultCallback);
    }

    public void registerForActivityResultFast(ActivityResultCaller activityResultCaller) {
        this.activityResultLauncher = activityResultCaller.registerForActivityResult(targetActivityResultContract, getOnTargetActivityResultCallback());
    }

    public void launcher(T data) {
        if (this.activityResultLauncher == null) {
            throw new NullPointerException("请先注册!");
        }
        this.activityResultLauncher.launch(AppIntentUtils.getBundleByData(data));
    }

    public void launcher(Bundle data) {
        if (this.activityResultLauncher == null) {
            throw new NullPointerException("请先注册!");
        }
        this.activityResultLauncher.launch(data);
    }

}
